﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Lon.IO;
using Lon.Server;

namespace Lon.UI
{
    public partial class FormFilter : Form
    {
        bool[] typeList;

        public FormFilter(bool[] typeList)
        {
            InitializeComponent();
            this.typeList = typeList;
            this.clbDataTypeFilter.Items.Clear();
            foreach (String key in NetRawDataRec.dataTypeNameDict.Keys)
            {
                this.clbDataTypeFilter.Items.Add(key);
                this.clbDataTypeFilter.SetItemCheckState(
                    this.clbDataTypeFilter.Items.Count-1,
                    typeList[NetRawDataRec.dataTypeNameDict[key]]?CheckState.Checked:CheckState.Unchecked);

            }

        }

        private void clb_SelectedIndexChanged(object sender, EventArgs e)
        {
         
        }

        private void btnAllEnable_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.clbDataTypeFilter.Items.Count; i++)
            {
                

                this.clbDataTypeFilter.SetItemCheckState(i, CheckState.Checked);
            }
        }

        private void btnAllDisable_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.clbDataTypeFilter.Items.Count; i++)
            {
                this.clbDataTypeFilter.SetItemCheckState(i, CheckState.Unchecked);
            }
        }

        private void FormFilter_FormClosing(object sender, FormClosingEventArgs e)
        {
            for (int i = 0; i < this.clbDataTypeFilter.Items.Count; i++)
            {
                String str = (String)this.clbDataTypeFilter.Items[i];
                if (!NetRawDataRec.dataTypeNameDict.ContainsKey(str)) continue;
                int typeId = NetRawDataRec.dataTypeNameDict[str];
                typeList[(byte)typeId] = this.clbDataTypeFilter.GetItemChecked(i);

            }
        }
    }
}
